package com.example.ymm.modules1.service.impl.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.my.user.DbGood;
import com.example.ymm.modules1.mapper.my.user.DbGoodMapper;
import com.example.ymm.modules1.query.DbGoodQueryCriteria;
import com.example.ymm.modules1.service.user.DbGoodService;
import com.example.ymm.util.QueryHelpPlus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@Slf4j
public class DbGoodServiceImpl extends BaseServiceImpl<DbGoodMapper, DbGood> implements DbGoodService {

    @Override
    public TableList<DbGood> list(DbGoodQueryCriteria criteria, YmPageDto pageDto) {
        IPage<DbGood> page = new Page<DbGood>(pageDto.getPage(),pageDto.getPageSize());
        QueryWrapper predicate = QueryHelpPlus.getPredicate(DbGood.class, criteria);
        predicate.orderByDesc("create_time");
        baseMapper.selectPage(page, predicate);
        TableList<DbGood> tableList=new TableList(page);
        return tableList;
    }

    public List<DbGood> queryAll(DbGoodQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(DbGood.class, criteria);
        predicate.orderByDesc("create_time");
        List<DbGood> result =baseMapper.selectList(predicate);
        return result;
    }
}
